<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
	</head>

	<body style="padding: 0px;">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<form id="ff">
			<table id="table" class="displaytable" cellpadding="6" style="padding: 20px">
				<tr>
					<td width="20%"><h id="star">* </h>盘存人</td>
					<td width="30%">
						<input type="text" style="width: 80%;" name="OPERATOR" id="input_OPERATOR" class="easyui-combobox" data-options="required:true" />
					</td>
					<td width="20%"><h id="star">* </h>盘存时间</td>
					<td width="30%">
						<input type="text" style="width: 80%;" name="INVENTORY_DATE" id="input_INVENTORY_DATE" class="easyui-datebox" data-options="required:true" />
					</td>
				</tr>
				<tr>
					<td width="20%"><h id="star">* </h>账面库存量</td>
					<td width="30%">
						<input type="text" style="width: 80%;" name="BOOKSTOCK" id="input_BOOKSTOCK" class="easyui-numberbox" data-options="disabled:true,required:true" />
					</td>
					<td width="20%"><h id="star">* </h>盘点库存量</td>
					<td width="30%">
						<input type="text" style="width: 80%;" name="REALSTOCK" id="input_REALSTOCK" class="easyui-textbox" data-options="required:true" />
					</td>
				</tr>
			</table>
			<table>
				<tr style="display: none;">
					<td width="20%"><h id="star">* </h>入库单ID</td>
					<td width="30%">
						<input type="text" style="width: 80%;" name="ORDER_ID" id="input_ORDER_ID" class="easyui-numberbox" data-options="required:true" />
					</td>
				</tr>
			</table>
			<div id="dlg" class="easyui-dialog" closed="true" style="width:560px;height:400px;padding:10px">
				<iframe id="ifrmEdit" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>
			</div>
			<div id="new_footer"></div>
		</form>
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src="../../../JS/MarketShareFunction/DialogShareFunction.js"></script>
	</body>
	<script type="text/javascript">
		var content;
		var id = getID();
		var currid;
		var isVerify;
		var receipts_type = RECEIPT_VERIFY_SYMBOL+RECEIPT_UNVERIFY_SYMBOL + RECEIPT_PRINT_SYMBOL + RECEIPT_EXPORT_SYMBOL;
		receipts_type += RECEIPT_SAVE_SYMBOL + RECEIPT_ADD_SYMBOL + RECEIPT_DELETE_SYMBOL;
		content = AddReceiptsToolBar(receipts_type, "");
		$("#toolbar").append(content);
		addDialogFooter($("#new_footer"));

		initCombobox();
		$(document).ready(function(){
			if(id != AddFlag) {
				currid = id;
				var _url = RemoteLinkAddress + '/frozen/inventory/findbyid.do?ID=' + currid;
				getRemoteData(_url);
			} else {
				currid = AddFlag;
			}
		})

		//新建按钮
		function newdata() {
			$("#verifydisplay").empty(); //去掉审核或者未审核的图片
			isVerify = 0; //将状态改为未审核
			currid = AddFlag;
			resetData();
		}

		//
		function save() {
			if(!isTrueData()) {
				$.messager.alert("错误", "请检查数据的完整性！");
				return;
			}
			var _url;
			if(currid == AddFlag) {
				_url = RemoteLinkAddress + "/frozen/inventory/save.do"
			} else {
				if(isVerify == 1) {
					$.messager.alert("警告", "表单已审核不能修改!");
					return;
				}
				_url = RemoteLinkAddress + "/frozen/inventory/update.do";
			}
			saveData(_url);
		}

		//删除按钮
		function deletedata() {
			if(isVerify == 1) {
				$.messager.alert("警告", "表单已审核，无法删除");
				return;
			}
			if(currid == AddFlag) {
				$.messager.alert("警告", "该页面为新增页面，无法删除");
				return;
			}
			$.messager.confirm("确认", "是否删除", function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/frozen/inventory/delete.do", {
						"ID": currid,
					}, function(result) {
						if(result.msg == "success") {
							$.messager.alert({
								title: '成功',
								msg: '删除成功!'
							});
							var parentLocation;
							parentLocation = searchParent("LeasingOperationDetail.html");
							parentLocation.dialogClose();
							reflashDataGrid();
						} else {
							$.messager.alert({
								title: 'Error',
								msg: result.msg
							});
						}
					}, 'json');
				}
			});
		}

		//审核按钮
		function verifydata() {
			if(isVerify == 1) {
				$.messager.alert("警告", "表单已审核，无须再审");
				return;
			}
			if(currid == AddFlag) {
				$.messager.alert("警告", "该页面为新增页面，不能执行");
				return;
			}
			$.messager.confirm("确认", "是否审核", function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/frozen/inventory/verify.do", {
						"ID": currid,
					}, function(result) {
						if(result.msg == "success") {
							$.messager.alert({
								title: '成功',
								msg: '审核成功!'
							});
							verifyStatus_Market(1, true);
							isVerify = 1;
							reflashDataGrid();
						} else {
							$.messager.alert({
								title: 'Error',
								msg: result.msg
							});
						}
					}, 'json');
				}
			});
		}

		//弃审按钮
		function unverifydata() {
			if(isVerify == 0) {
				$.messager.alert("警告", "表单已弃审，无须再审");
				return;
			}
			if(currid == AddFlag) {
				$.messager.alert("警告", "该页面为新增页面，不能执行");
				return;
			}
			$.messager.confirm('Confirm', '是否弃审', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/frozen/inventory/unverify.do", {
							"ID": currid,
						},
						function(result) {
							if(result.msg == "success") {
								$.messager.alert({
									title: '成功',
									msg: '弃审成功!'
								});
								verifyStatus_Market(0, true);
								isVerify = 0;
								reflashDataGrid();
							} else {
								$.messager.alert({
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}

		//打印按钮
		function print() { //打印
			if(currid == AddFlag) {
				$.messager.alert('警示', "当前页面为新增页面，不可打印！");
				return;
			}
			if(currid == AddFlag || isVerify != 1) {
				$.messager.alert('警示', "该页面未审核，不可以打印！");
				return;
			}
			var pLocation = "LeasingOperationPrintInventoryStorage.html?id=" + currid;
			window.open(pLocation);
		}
		
		//导出
		function exportExcel(){
			if(currid == AddFlag) {
				$.messager.alert("警告", "该订单为新增订单，无法导出Excel！");
				return;
			}
			$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
				if(r) {
					$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
						type: "get",
						data: {
							"ID": currid
						},
						url: RemoteLinkAddress + "/frozen/inventory/excelorder.do",
						dataType: "json", //服务器返回的数据类型
						success: function(result) {
							window.location.href = result.path;
						}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
						error: function(xhr, status, error) {
							$.messager.alert("错误", "请求失败!");
						}
					});
				}
			});
		}

		function getRemoteData(_url) {
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result != null) {
						isVerify = result.ISVERIFY;
						currid = result.ID;
						getDialogData(result);
						verifyStatus_Market(isVerify, true);
					}
				}
			});
		}


		//判断数据的完整性
		function isTrueData() {
			var tip = true;
			$("#table input[name]").each(function(index){
				if($(this).attr("name") === "BOOKSTOCK"){
					return ;
				}
				if($(this).val().trim().length == 0){
					tip = false;
					return ;
				}
			});
			return tip;
		
		}

		//提交数据
		function saveData(_url) {
			var _data = submitDialogData();
			if(currid != AddFlag) {
				_data.ID = currid;
			}
			$.ajax({
				dataType: 'JSON',
				url: _url,
				data: _data,
				type: "post",
				success: function(result) {
					if(result.msg.search("success") > -1) {
						$.messager.alert("消息","保存成功");
						var parentLocation;
						parentLocation = searchParent("LeasingOperationDetail.html");
						parentLocation.dialogClose();
						reflashDataGrid();
					} else {
						$.messager.alert("提示", "保存失败");
					}
				},
				error: function(result) {
					$.messager.alert("错误", "保存失败");
				}
			});
		}
		
		//刷新datagrid
		function reflashDataGrid(){
			var _url = RemoteLinkAddress + "/frozen/inorder/findbyid.do?ID=" + 　$("#input_ORDER_ID").val();
			var parentLocation;
			parentLocation = searchParent("LeasingOperationDetail.html");
			parentLocation.getRemoteData(_url);
		}
		
		function initCombobox() {
			$("#input_OPERATOR").combobox({
				valueField: 'USERNAME',
				textField: 'USERNAME',
				panelHeight: 150,
				mode: 'remote',
				method: 'get',
				url: RemoteLinkAddress + "/user/listall.do",
			});
			
			var data;
			var parentLocation;
			parentLocation = searchParent("LeasingOperationDetail.html");
			data = parentLocation.ReturnDetailData();
			$("#input_BOOKSTOCK").val(data.CURR_AMOUNT);
			$("#input_ORDER_ID").val(data.ID);
		}
	</script>

</html>